/**
 * Captain
 * © 2018 Captain copyright，All rights reserved.
 * http://www.sccaptain.com.cn
 * 
 * JAVA : 8
 * 文  件  名: CommentServiceImpl.java
 * 创  建  人: QinYoubin (qin.youbin@sccaptain.com.cn)
 * 创建时间: 2018年4月27日 上午10:20:02
 * 版         本: 1.0.0
 * 备         注:
 * 修订历史:
 */
package com.material.c2c.message.service;

import java.util.Date;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.cpt.framework.core.OperationResult;
import com.material.c2c.config.MessageStatus;
import com.material.c2c.core.UUIDGenerator;
import com.material.c2c.message.dao.CommentDao;
import com.material.c2c.message.entity.YHLY;

/**
 * 用户留言
 * @since 1.0
 * @version 1.0
 * @author QinYoubin (qin.youbin@sccaptain.com.cn)
 */
@Service
public class CommentServiceImpl implements CommentService{
  @Resource
  private CommentDao commentDao;
  
  @Override
  @Transactional
  public OperationResult add(YHLY yhly) {
    yhly.setId(UUIDGenerator.generateUUIDStr());
    yhly.setLysj(new Date());
    yhly.setSfhf(MessageStatus.NO);
    yhly = commentDao.add(yhly);
    if(yhly == null) {
      return OperationResult.failed("留言失败!");
    }
    return OperationResult.SUCCEED;
  }
  @Override
  @Transactional
  public OperationResult delete(String id) {
    commentDao.delete(id);
    return OperationResult.SUCCEED;
  }
  @Override
  public Page<YHLY> listByDdid(String ddid,Pageable pageable){
    return commentDao.findByDdidOrderByLysjDesc(ddid, pageable);
  }
}
